{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "## 元组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=10, tm_mday=25, tm_hour=11, tm_min=31, tm_sec=2, tm_wday=0, tm_yday=298, tm_isdst=0)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "names = \"ruihan\",\"wuwei\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('ruihan', 'wuwei')"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.count(\"ruihan\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names.index(\"ruihan\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字典\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 字典的创建方式\n",
    "* 直接创建字典，按照字典的结构 dict = {key1: value1, key2: value2, ...}\n",
    "dict()创建字典 dict(key1 = value1, key2 = value2, ...)\n",
    "* 创建空字典，通过添加值的方法创建字典\n",
    "* 字典的一些性质"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种创建字典方法\n",
    "stu_info ={\n",
    "      \"stu10001\":\"Alex\",\n",
    "      \"stu10002\":\"Jack\",\n",
    "      \"stu10003\":\"Linda\"\n",
    "}\n",
    "\n",
    "stu10001={\n",
    "      \"name\":\"Alex\",\n",
    "      \"age\":\"18\",\n",
    "      \"job\":\"student\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu10001': 'Alex', 'stu10002': 'Jack', 'stu10003': 'Linda'}\n"
     ]
    }
   ],
   "source": [
    "print(stu_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 直接按照字典的格式创建 ： {key1：value1，key2：value2，...}\n",
    "stu_info = {\n",
    "    \"stu_10001\":\"alex\",\n",
    "    \"stu_10002\":\"jack\",\n",
    "    \"stu_10003\":\"marry\",\n",
    "           }\n",
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.dict()函数来创建字典： dict(key1=value1,key2=value2,...)\n",
    "stu_info1 = dict(\n",
    "    stu_10001 = \"alex\",\n",
    "    stu_10002 = \"jack\",\n",
    "    stu_10003 = \"marry\",\n",
    ")\n",
    "stu_info1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu10001': 'Alex', 'stu10002': 'Jack', 'stu10003': 'Linda'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 第三种，新建空字典，增加值的方式\n",
    "\n",
    "stu_info_03 = {}\n",
    "stu_info_03['stu10001'] = \"Alex\"\n",
    "stu_info_03['stu10002'] = \"Jack\"\n",
    "stu_info_03['stu10003'] = \"Linda\"\n",
    "stu_info_03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2 = {}\n",
    "stu_info2 [\"stu_10001\"] =\"alex\"\n",
    "stu_info2 [\"stu_10002\"] =\"jack\"\n",
    "stu_info2 [\"stu_10003\"] =\"marry\"\n",
    "stu_info2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['stu_10001', 'stu_10002', 'stu_10003'])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values(['alex', 'jack', 'marry'])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
